package com.muye.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.muye.dianli.R;
import com.muye.field.OrderListData;
import com.zvezda.android.utils.BaseUtils;
import com.zvezda.disply.utils.DisplayConfig;
import com.zvezda.disply.utils.DisplayConst;
import com.zvezda.disply.utils.DisplayManager;

/**
 * 我的订单适配器
 * 
 * @author TangChao
 *
 */
public class OrderListAdapter extends BaseAdapter
{
	private Context context;
	
	private List<OrderListData> arrayList;
	
	private String path;
	
	public OrderListAdapter(Context context, List<OrderListData> arrayList, String path)
	{
		super();
		this.context = context;
		this.arrayList = arrayList;
		this.path = path;
	}
	
	@Override
	public int getCount()
	{
		if (arrayList != null)
		{
			return arrayList.size();
		}
		return 0;
	}
	
	@Override
	public OrderListData getItem(int position)
	{
		if (arrayList != null)
		{
			return arrayList.get(position);
		}
		return null;
	}
	
	@Override
	public long getItemId(int position)
	{
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final ViewHolder viewHolder;
		if (convertView == null)
		{
			convertView = LayoutInflater.from(context).inflate(R.layout.order_list_adapter_layout, null);
			viewHolder = new ViewHolder();
			viewHolder.orderImage = (ImageView) convertView.findViewById(R.id.order_list_adapter_image_view);
			viewHolder.titleText = (TextView) convertView.findViewById(R.id.order_list_adapter_text_view0);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (viewHolder != null)
		{
			OrderListData item = arrayList.get(position);
			viewHolder.titleText.setText(item.title);
			DisplayManager.getInstance().open(context);
			DisplayConfig displayConfig = new DisplayConfig();
			displayConfig.path = BaseUtils.getFilePath(path, item.logoUrl);
			displayConfig.url = item.logoUrl;
			displayConfig.defaultRes = R.drawable.ic_launcher;
			displayConfig.h = 96;
			displayConfig.w = 96;
			displayConfig.zoomModel = DisplayConst.ZOOM_THUMBNAIL;
			displayConfig.imageView = viewHolder.orderImage;
			DisplayManager.getInstance().display(displayConfig);
		}
		return convertView;
	}
	
	private class ViewHolder
	{
		ImageView orderImage;
		
		TextView titleText;
	}
}
